#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+100;
int T,n,a[N],b[N];
int main() {
    cin >> T;
    while (T--)
    {
        cin >> n;
        for(int i=1;i<=n;i++) cin >> a[i];
        for(int i=1;i<=n;i++) cin >> b[i];
        int sum_a = 0, sum_b = 0,x=0,y=0;
        for(int i=1;i<=n;i++) {
            if(a[i]==-1 && b[i]!=-1)  sum_b += b[i];
            else if(a[i]!=-1 && b[i] == -1)  sum_a += a[i];
            else if(a[i] == 1 && b[i] == 1)  x += 1;
            else if(a[i] == -1&& b[i] == -1)  y += 1;
            else {
                sum_a += a[i];
                sum_b += b[i];
            }
        }
        // cout << sum_a << " " << sum_b << endl;
        //有x个正1，有y个-1
        for(int i=1;i<=x;i++) {
            if(sum_a < sum_b) sum_a+=1;
            else sum_b += 1;
        }
        for(int i=1;i<=y;i++) {
            if(sum_a>sum_b) sum_a += -1;
            else sum_b += -1;
        }
        cout << min(sum_a,sum_b) << endl;
    }
    return 0;
}